﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.SoldierArchives.BLL;
using Yipusoft.SoldierArchives.Model;
using Yipusoft.TranslateApprove.BLL;
using Yipusoft.TranslateApprove.Model;

public partial class Police_TranslateProcess_TanslateDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["Fid"] != null)
            {
                bind();
            }
        }
    }

    void bind()
    {
        TranslateInfo info = Translate.GetDetail(new Guid(Request["Fid"]));
        lblName.Text = info.SoldierName;
        lblNewDepartment.Text = info.NewDepartment;
        if (info.TID == 1)
        {
            lblOldDepartment.Text = info.OldDepartment2;
        }
        else
        {
            lblOldDepartment.Text = info.OldDepartment;
        }
        lblRanker.Text = info.Ranker;
        lblSex.Text = info.Sex;
        lblTanslateType.Text = getType(info.TID);
        lblDateArmy.Text = info.DateArmy.ToShortDateString();
        List<TranslateLogInfo> logs = TranslateLogs.GetListByFID(info.ID);

        if (info.TID == 1)
        {
            trOrder.Visible = false;
        }
        else
        {
            trTreat.Visible = false;
        }

        for (int i = 0; i < logs.Count; i++)
        { //请示
            TranslateLogInfo log = logs[i];
            if (TranslateProcess.GetDetail(log.PID).ProcessName == "请示")
            {
                //trApply.Visible = true;
                ApplyInfo Ainfo = Apply.GetApply(log.DID);
                lbtApplay.Text = Ainfo.Title;
                lblName0.Text = Yipusoft.Account.BLL.User.GetUser(Ainfo.UserID).UserName;
                lkbApply.PostBackUrl = "../TranslateApprove/AppalyNew.aspx?id=" + Ainfo.AID;


                BindTable(Ainfo.AID);
                if (Ainfo.FilePath == "")
                {
                    lbtApplay.NavigateUrl = "~/ContentNoExist.aspx";
                }
                else
                {
                    lbtApplay.NavigateUrl = "../TranslateApprove/WordFile/" + Ainfo.FilePath;
                }
            }
            if (TranslateProcess.GetDetail(log.PID).ProcessName == "填写商调函")
            {

                trTreat.Visible = true;
                lbtTransferTreat.NavigateUrl = "../TranslateDocument/BusinessLetter.aspx?ID=" + log.DID;
            }
            if (TranslateProcess.GetDetail(log.PID).ProcessName == "开调令")
            {
                trOrder.Visible = true;
                lbtTransferOrder.NavigateUrl = "../TranslateDocument/TransferOrder.aspx?ID=" + log.DID;
            }
            if (TranslateProcess.GetDetail(log.PID).ProcessName == "上传对方介绍信")
            {
                trIntroFile.Visible = true;
                TranslateIntroFileInfo Finfo = TranslateIntrolFile.GetDetail(log.DID);
                if (Finfo.PilePath == "")
                {
                    lbtTranslateIntroFile.NavigateUrl = "~/ContentNoExist.aspx";
                }
                else
                {
                    lbtTranslateIntroFile.NavigateUrl = "../TranslateDocument/WordFile/" + Finfo.PilePath;
                }

                lkbOtherIntroLetter.PostBackUrl = "../TranslateDocument/TranslateIntroFile.aspx?id=" + Finfo.ID;
            }
            if (TranslateProcess.GetDetail(log.PID).ProcessName == "填写本单位介绍信")
            {
                trIntroLetter.Visible = true;
                lbtTranslateIntroLetter.NavigateUrl = "../TranslateDocument/IntroduceLetter.aspx?ID=" + log.DID;
                //lbtIntroLetterUpdate.PostBackUrl = "../TranslateDocument/IntroduceLetterUpdate.aspx?id="+log.DID;
            }
        }
        GetState();

    }

    public string getType(int TID)
    {

        switch (TID)
        {
            case 1:
                return "调入";
            case 2:
                return "调出";
            case 3:
                return "内部调动";
            default:
                return "";
        }

    }

    public void GetState()
    {
        TranslateLogInfo log = TranslateLogs.GetLastDetail(new Guid(Request["Fid"]));
        if (log != null)
        {


            TranslateProcessInfo PInfo = TranslateProcess.GetDetail(log.PID);

            lblState.Text = PInfo.ProcessName + "完成";

            if (TranslateProcess.GetNextDetail(log.PID) != null)
            {
                if (TranslateProcess.GetDetail(log.PID).ProcessName == "请示")
                {
                    Guid AID = log.DID;
                    string where = "Fid='" + AID + "'";
                    List<SetupLogInfo> list = SetupLog.GetList(where);
                    if (list.Count > 0)
                    {
                        lblState.Text = SetupLog.GetCurrentState(log.DID);
                        if (lblState.Text == "审批通过")
                        {
                            lblState.ForeColor = System.Drawing.Color.Red;
                        }
                    }
                }
                if (TranslateProcess.GetNextDetail(log.PID).ProcessName == "士兵报到")
                {
                    lblState.Text = TranslateProcess.GetNextDetail(log.PID).ProcessName + "中...";
                }

            }
            else
            {
                lblState.ForeColor = System.Drawing.Color.Red;
            }

        }


    }

    private void BindTable(Guid FID)
    {
        List<SetupLogInfo> list = SetupLog.GetList(" Fid='" + FID + "'");
        if (list.Count > 1)
        {
            foreach (SetupLogInfo info in list)
            {
                if (info.Remark != "")
                {
                    lblRemark.Text += info.Remark + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;审批人：" + info.UserName + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;审批时间：" + info.RTime + "<br/>";
                }
            }
        }
        else
        {
            lblRemark.Text = "没有审批记录！";
        }
    }
    protected void lkbApply0_Click(object sender, EventArgs e)
    {

    }

   
}
